#! /bin/sh -e

# All lines beginning with `# DPATCH:' are a description of the patch.
# DP: Description: use -Wno-format on tests that cannot be adjusted other ways.
# DP: Author: Kees Cook <kees@ubuntu.com>
# DP: Ubuntu: https://bugs.launchpad.net/bugs/344502

dir=
if [ $# -eq 3 -a "$2" = '-d' ]; then
    pdir="-d $3"
    dir="$3/"
elif [ $# -ne 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
    -patch)
        patch $pdir -f --no-backup-if-mismatch -p1 < $0
        #cd ${dir}gcc && autoconf
        ;;
    -unpatch)
        patch $pdir -f --no-backup-if-mismatch -R -p1 < $0
        #rm ${dir}gcc/configure
        ;;
    *)
        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
        exit 1
esac
exit 0

diff -uNrp a/src/gcc/testsuite/gcc.c-torture/execute/vfprintf-chk-1.x b/src/gcc/testsuite/gcc.c-torture/execute/vfprintf-chk-1.x
--- a/src/gcc/testsuite/gcc.c-torture/execute/vfprintf-chk-1.x	1969-12-31 16:00:00.000000000 -0800
+++ b/src/gcc/testsuite/gcc.c-torture/execute/vfprintf-chk-1.x	2009-03-17 16:57:17.000000000 -0700
@@ -0,0 +1,5 @@
+# Implement "/* { dg-options "-U_FORITFY_SOURCE" } */", due to
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20567
+
+set additional_flags "-U_FORTIFY_SOURCE"
+return 0
diff -uNrp a/src/gcc/testsuite/gcc.c-torture/execute/vprintf-chk-1.x b/src/gcc/testsuite/gcc.c-torture/execute/vprintf-chk-1.x
--- a/src/gcc/testsuite/gcc.c-torture/execute/vprintf-chk-1.x	1969-12-31 16:00:00.000000000 -0800
+++ b/src/gcc/testsuite/gcc.c-torture/execute/vprintf-chk-1.x	2009-03-20 00:25:19.000000000 -0700
@@ -0,0 +1,5 @@
+# Implement "/* { dg-options "-U_FORITFY_SOURCE" } */", due to
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20567
+
+set additional_flags "-U_FORTIFY_SOURCE"
+return 0
diff -uNrp a/src/gcc/testsuite/gcc.dg/charset/builtin2.c b/src/gcc/testsuite/gcc.dg/charset/builtin2.c
--- a/src/gcc/testsuite/gcc.dg/charset/builtin2.c	2005-11-28 21:17:20.000000000 -0800
+++ b/src/gcc/testsuite/gcc.dg/charset/builtin2.c	2009-03-17 16:59:25.000000000 -0700
@@ -3,7 +3,7 @@
 
 /* { dg-do compile } */
 /* { dg-require-iconv "IBM1047" } */
-/* { dg-options "-O2 -fexec-charset=IBM1047" } */
+/* { dg-options "-O2 -fexec-charset=IBM1047 -Wno-format" } */
 /* { dg-final { scan-assembler-not "printf" } } */
 /* { dg-final { scan-assembler-not "fprintf" } } */
 /* { dg-final { scan-assembler-not "sprintf" } } */
diff -uNrp a/src/gcc/testsuite/gcc.dg/format/format.exp b/src/gcc/testsuite/gcc.dg/format/format.exp
--- a/src/gcc/testsuite/gcc.dg/format/format.exp	2008-12-05 12:35:34.000000000 -0800
+++ b/src/gcc/testsuite/gcc.dg/format/format.exp	2009-03-17 17:08:18.000000000 -0700
@@ -26,7 +26,7 @@ load_lib gcc-dg.exp
 load_lib torture-options.exp
 
 torture-init
-set-torture-options [list { } { -DWIDE } ]
+set-torture-options [list { -Wformat=0 } { -DWIDE -Wformat=0 } ]
 
 dg-init
 gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] ""
diff -uNrp a/src/gcc/testsuite/gcc.dg/pr30473.c b/src/gcc/testsuite/gcc.dg/pr30473.c
--- a/src/gcc/testsuite/gcc.dg/pr30473.c	2007-02-02 04:21:13.000000000 -0800
+++ b/src/gcc/testsuite/gcc.dg/pr30473.c	2009-03-17 17:01:13.000000000 -0700
@@ -1,7 +1,7 @@
 /* PR middle-end/30473 */
 /* Make sure this doesn't ICE.  */
 /* { dg-do compile } */
-/* { dg-options "-O2" } */
+/* { dg-options "-O2 -Wno-format" } */
 
 extern int sprintf (char *, const char *, ...);
 
diff -uNrp a/src/gcc/testsuite/gcc.dg/pr38902.c b/src/gcc/testsuite/gcc.dg/pr38902.c
--- a/src/gcc/testsuite/gcc.dg/pr38902.c	2009-03-16 18:23:01.000000000 -0700
+++ b/src/gcc/testsuite/gcc.dg/pr38902.c	2009-03-17 17:02:06.000000000 -0700
@@ -1,6 +1,6 @@
 /* PR target/38902 */
 /* { dg-do run } */
-/* { dg-options "-O2 -fstack-protector" } */
+/* { dg-options "-O2 -fstack-protector -Wno-format" } */
 /* { dg-require-effective-target fstack_protector } */
 
 #ifdef DEBUG
